import json
import struct
from google.protobuf import json_format
import portal_pb2

with open("pb.txt", 'rb') as f:
    data = f.read()

a, b, c, d = struct.unpack("=Hi71s602s", data)
print(a)
print(b)
first = portal_pb2.AuthReq()
first.ParseFromString(c)
first_1 = first.AppUUID
first_2 = first.ChannelID
first_3 = first.DeviceID
first_4 = first.AccountID
first_5 = first.AuthInfo
first_6= first.Pwd
print("AuthReq1:",first_1, first_2, first_3, first_4,first_5,first_6)

a,b,c,d = struct.unpack("=Hi57s539s",d)
second = portal_pb2.NoticeBoardReq()
second = portal_pb2.NoticeBoardReq()
second.ParseFromString(c)
second1=second.ChannelID
second2=second.DeviceID
second3=second.DeviceType
print("NoticeBoardReq2:",second1,second2,second3)

a,b,c,d = struct.unpack("=Hi480s53s",d)
third = portal_pb2.NoticeBoardRsp()
third.ParseFromString(c)
third1 = third.NoticeBoardInfoArray
jsonStringRequest1 = json_format.MessageToJson(third1[0])
jsonStringRequest2 = json_format.MessageToJson(third1[1])
a1 = json.loads(jsonStringRequest1)
a2 = json.loads(jsonStringRequest2)
print("NoticeBoardRsp3中数据:")
print(a1)
print(a2)


a,b,c = struct.unpack("=Hi47s",d)
fourth = portal_pb2.AuthRsp()
fourth.ParseFromString(c)
fourth1=fourth.Code
fourth2=fourth.Msg
fourth3=fourth.AppUUID
fourth4=fourth.AccountID
fourth5=fourth.AccountName
fourth6=fourth.Token
fourth7=fourth.TokenExpiredTime
fourth8=fourth.OneArea
fourth9=fourth.TokenStr
fourth10=fourth.LoginHost
print("AuthRsp4:",fourth1,fourth2,fourth3,fourth4,fourth5,fourth6,fourth7,fourth8,fourth9,fourth10)


